import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "../components/Login";
import Home from "../components/Home";
import el from "element-ui/src/locale/lang/el";

Vue.use(VueRouter)

const router = new VueRouter({
  routes:[
    //  重定向
    { path: '/', redirect:'/login'},
    { path:'/login', component:Login},
    { path:'/home',  component:Home}
  ]
})

router.beforeEach((to, from, nest)=>{
  if (to.path === '/login'){
    return nest();
  }else if(!window.sessionStorage.getItem('token')){
    return nest('/login');
  }else {
    return nest();
  }
})

export default router
